home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
xsw
/
libmem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-09
|
4KB
|
146 lines
/*
* @(#) libmem.c 12.1 95/05/09
*/
/***************************************************************************
*
* Copyright (c) 1990 The Santa Cruz Operation, Inc.
*
* All rights reserved. No part of this program or publication may be
* reproduced, transmitted, transcribed, stored in a retrieval system,
* or translated into any language or computer language, in any form or
* by any means, electronic, mechanical, magnetic, optical, chemical,
* biological, or otherwise, without the prior written permission of:
*
* The Santa Cruz Operation , Inc. (408) 425-7222
* 400 Encinal St., Santa Cruz, California 95060 USA
*
**************************************************************************/
/*
* S000, 30-Sep-92, rickra
* Added copyright and modification history
*/
/*LINTLIBRARY*/
/*+-------------------------------------------------------------------------
libmem.c -- /dev/mem routines for SCO UNIX/386 (maybe other *NIX)
...!{gatech,emory}!n4hgf!wht
Defined functions:
minit(write_needed)
mread(caddr,maddr,len)
mwrite(maddr,caddr,len)
routines were originally written by Mike "Ford" Ditto: kudos!!!
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:09-25-1990-05:11-wht@n4hgf-release heh-heh x0.22 preliminary */
/*:09-20-1990-00:09-wht@n4hgf-scales, sysinfo/minfo, bootinfo working */
/*:09-15-1990-06:33-wht@n4hgf-adopt u386mon libraries */
/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.sysware.dk S5R31 updates */
/*:08-02-1990-15:36-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
/*:12-07-1988-22:06-wht-put in test for initialized fdmem */
/*:10-27-1988-22:44-wht-creation of file */
#include <sys/types.h>
#include <fcntl.h>
#include "include/libmem.h"
void leave_text ();
extern int errno;
static int fdmem = -2;
daddr_t lseek ();
/*+-------------------------------------------------------------------------
minit(write_needed)
--------------------------------------------------------------------------*/
void
minit (write_needed)
int write_needed;
{
if (fdmem >= 0)
return;
if ((fdmem = open ("/dev/mem", O_RDONLY, 0)) < 0)
leave_text ("can't open /dev/mem", fdmem);
/*
if((fdmem=open("/dev/mem",(write_needed) ? O_RDWR : O_RDONLY,0)) < 0)
leave_text("can't open /dev/mem",fdmem);
*/
} /* end of minit */
/*+-------------------------------------------------------------------------
mread(caddr,maddr,len)
--------------------------------------------------------------------------*/
void
mread (caddr, maddr, len)
caddr_t caddr;
daddr_t maddr;
int len;
{
char s80[80];
#if defined(M_I286)
maddr &= 0xFFFFL;
#endif
if (fdmem == -2)
leave_text ("minit() not called", 1);
if (lseek (fdmem, maddr, 0) == -1L)
{
(void) sprintf (s80, "mem seek err (%08lx)", maddr);
leave_text (s80, 1);
}
if (read (fdmem, caddr, len) != len)
{
(void) sprintf (s80,
"mem read errno %d len %d addr %08lx", errno, len, maddr);
leave_text (s80, 1);
}
} /* end of mread */
/*+-------------------------------------------------------------------------
mwrite(maddr,caddr,len)
--------------------------------------------------------------------------*/
#ifdef MWRITE_NEEDED
void
mwrite (maddr, caddr, len)
daddr_t maddr;
caddr_t caddr;
int len;
{
char s80[80];
#if defined(M_I286)
maddr &= 0xFFFFL;
#endif
if (fdmem == -2)
leave_text ("minit() not called", 1);
if (lseek (fdkmem, kaddr, 0) == -1L)
{
(void) sprintf (s80,
"/dev/kmem seek error addr %08lx", kaddr);
leave_text (s80, 255);
}
if (write (fdkmem, caddr, len) != len)
{
(void) sprintf (s80,
"/dev/kmem write error addr %08lx len %08lx", kaddr, len);
leave_text (s80, 255);
}
} /* end of mwrite */
#endif /* MWRITE_NEEDED */
/* vi: set tabstop=4 shiftwidth=4: */